/*
 * Access control methods (acm). Methods can have permission assigned to them 
 * and allow Roles to determine if access is allowed.
 * 
 * @author: Oren Zamir
 */
package org.valire.usermanagement.beans;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.valire.util.persistency.BaseEntity;
import org.valire.util.processors.ValireDtoCheck;


/**
 * The Class Roles.
 */
@ValireDtoCheck(referenceClasses = {"org.valire.usermanagement.NapDto"})
@Entity(name = "NODE_ACCESS_PERMISSION")
@Table(name = "NODE_ACCESS_PERMISSION")
public class NodeAccessPermission extends BaseEntity{

	private static final long serialVersionUID = -8448300147194797676L;

	/** The method name. */
	@Column(name = "NODE_REFERENCE")
	private Integer nodeReference;
	
	@Column(name = "TYPE")
	private Boolean type;
	
	/** The roles. */
	@ManyToMany( fetch = FetchType.EAGER)
	@JoinTable(name = "NODE_REFERENCES_ROLES", joinColumns = { @JoinColumn(name = "NODE_REFERENCE_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	private Set<Role> roles = new HashSet<Role>(0);

	/** The roles. */
	@ManyToMany( fetch = FetchType.EAGER)
	@JoinTable(name = "NODE_REFERENCES_USERS", joinColumns = { @JoinColumn(name = "NODE_REFERENCE_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") })
	private Set<User> users = new HashSet<User>(0);

	/**
	 * Sets the method name.
	 *
	 * @param methodName the new method name
	 */
	public void setNodeReference(Integer nodeReference) {
		this.nodeReference = nodeReference;
	}

	/**
	 * Gets the method name.
	 *
	 * @return the method name
	 */
	public Integer getNodeReference() {
		return nodeReference;
	}

	/**
	 * @param roles the roles to set
	 */
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	/**
	 * @return the roles
	 */
	public Set<Role> getRoles() {
		return roles;
	}


	/**
	 * @param roles the roles to set
	 */
	public void setUsers(Set<User> users) {
		this.users = users;
	}

	/**
	 * @return the roles
	 */
	public Set<User> getUsers() {
		return users;
	}

	public Boolean getType() {
		return type;
	}

	public void setType(Boolean type) {
		this.type = type;
	}
}
